﻿namespace AmazonS3PublishPlugin
{
    using System;
    using System.Collections.Generic;
    using System.Diagnostics;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Navigation;
    using Amazon.S3;
    using Amazon.S3.Model;
    using AmazonS3PublishPlugin.Helpers;

    /// <summary>
    /// Interaction logic for StandardUI.xaml
    /// </summary>
    public partial class StandardUI : UserControl
    {
        private readonly Publish _plugin;

        public StandardUI(Publish plugin)
        {
            this._plugin = plugin;
            DataContext = plugin;

            InitializeComponent();

            _plugin.PropertyChanged += (sender, e) =>
                {
                    if (e.PropertyName == "Data")
                    {
                        SecretAccessKey.Password = _plugin.Data.SecretAccessKey;
                    }
                };
        }

        private void CaptureUI_Click(object sender, RoutedEventArgs e)
        {
            Clipboard.SetImage(Helper.CaptureScreen((Visual)Tag, 96, 96));
        }

        private void Hyperlink_RequestNavigate(object sender, RequestNavigateEventArgs e)
        {
            Process.Start(new ProcessStartInfo(e.Uri.AbsoluteUri));
        }

        private void SecretAccessKey_PasswordChanged(object sender, RoutedEventArgs e)
        {
            _plugin.Data.SecretAccessKey = SecretAccessKey.Password;
        }

        private void OnLoaded(object sender, RoutedEventArgs e)
        {
            _plugin.UpdateCurrentJob();
        }

        private void ListBuckets_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            _plugin.ListBuckets();
        }

        private void ListBuckets_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            e.CanExecute = _plugin.CanListBuckets();
        }
    }
}